{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Setup"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Our targets come from the Penn World Tables and the OECD for the years 1995 to 2015."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:27:23.710720Z",
     "start_time": "2019-05-23T21:27:23.169011Z"
    }
   },
   "outputs": [],
   "source": [
    "from matplotlib import pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:27:23.715108Z",
     "start_time": "2019-05-23T21:27:23.712348Z"
    }
   },
   "outputs": [],
   "source": [
    "countries = ['us','fr','it','dk','sp','nl','se','de']\n",
    "countries = [c.upper() for c in countries]\n",
    "cnames = ['United States','France','Italy','Denmark','Spain','Netherlands','Sweden','Germany']\n",
    "co = dict(zip(countries,cnames))\n",
    "ce = dict(zip(cnames,countries))\n",
    "data = '../data_sources/'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We use Penn World Tables (https://www.rug.nl/ggdc/productivity/pwt/) for the capital to income ratio,  $\\frac{k}{y}$, consumption to income,  $\\frac{c}{y}$, and for relative GDP  $\\frac{y}{y_{US}}$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:27:26.449801Z",
     "start_time": "2019-05-23T21:27:23.916292Z"
    }
   },
   "outputs": [],
   "source": [
    "penn = pd.read_excel(data+'pwt/pwt90.xlsx',sheet_name='Data')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Select years and countries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:27:26.453853Z",
     "start_time": "2019-05-23T21:27:26.451682Z"
    }
   },
   "outputs": [],
   "source": [
    "years = range(1995,2016,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:27:26.462259Z",
     "start_time": "2019-05-23T21:27:26.455321Z"
    }
   },
   "outputs": [],
   "source": [
    "penn = penn[(penn['year'].isin(years)) & (penn['country'].isin(cnames))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>countrycode</th>\n",
       "      <th>country</th>\n",
       "      <th>currency_unit</th>\n",
       "      <th>year</th>\n",
       "      <th>rgdpe</th>\n",
       "      <th>rgdpo</th>\n",
       "      <th>pop</th>\n",
       "      <th>emp</th>\n",
       "      <th>avh</th>\n",
       "      <th>hc</th>\n",
       "      <th>...</th>\n",
       "      <th>csh_g</th>\n",
       "      <th>csh_x</th>\n",
       "      <th>csh_m</th>\n",
       "      <th>csh_r</th>\n",
       "      <th>pl_c</th>\n",
       "      <th>pl_i</th>\n",
       "      <th>pl_g</th>\n",
       "      <th>pl_x</th>\n",
       "      <th>pl_m</th>\n",
       "      <th>pl_k</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3035</th>\n",
       "      <td>DEU</td>\n",
       "      <td>Germany</td>\n",
       "      <td>Euro</td>\n",
       "      <td>1995</td>\n",
       "      <td>2444280.75</td>\n",
       "      <td>2376434.00</td>\n",
       "      <td>81.612900</td>\n",
       "      <td>37.939034</td>\n",
       "      <td>1527.978292</td>\n",
       "      <td>3.497632</td>\n",
       "      <td>...</td>\n",
       "      <td>0.135220</td>\n",
       "      <td>0.348669</td>\n",
       "      <td>-0.361674</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.033949</td>\n",
       "      <td>0.952057</td>\n",
       "      <td>1.559026</td>\n",
       "      <td>0.694944</td>\n",
       "      <td>0.655703</td>\n",
       "      <td>1.145803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3036</th>\n",
       "      <td>DEU</td>\n",
       "      <td>Germany</td>\n",
       "      <td>Euro</td>\n",
       "      <td>1996</td>\n",
       "      <td>2474957.50</td>\n",
       "      <td>2409760.75</td>\n",
       "      <td>81.870772</td>\n",
       "      <td>37.959774</td>\n",
       "      <td>1510.495404</td>\n",
       "      <td>3.511262</td>\n",
       "      <td>...</td>\n",
       "      <td>0.134964</td>\n",
       "      <td>0.346536</td>\n",
       "      <td>-0.353329</td>\n",
       "      <td>1.859867e-16</td>\n",
       "      <td>0.976098</td>\n",
       "      <td>0.934430</td>\n",
       "      <td>1.514511</td>\n",
       "      <td>0.696348</td>\n",
       "      <td>0.658500</td>\n",
       "      <td>1.094040</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3037</th>\n",
       "      <td>DEU</td>\n",
       "      <td>Germany</td>\n",
       "      <td>Euro</td>\n",
       "      <td>1997</td>\n",
       "      <td>2565733.00</td>\n",
       "      <td>2481533.50</td>\n",
       "      <td>81.993831</td>\n",
       "      <td>37.939022</td>\n",
       "      <td>1499.644241</td>\n",
       "      <td>3.524946</td>\n",
       "      <td>...</td>\n",
       "      <td>0.136400</td>\n",
       "      <td>0.346886</td>\n",
       "      <td>-0.342708</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.834261</td>\n",
       "      <td>0.826947</td>\n",
       "      <td>1.250930</td>\n",
       "      <td>0.656168</td>\n",
       "      <td>0.633227</td>\n",
       "      <td>0.969747</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3038</th>\n",
       "      <td>DEU</td>\n",
       "      <td>Germany</td>\n",
       "      <td>Euro</td>\n",
       "      <td>1998</td>\n",
       "      <td>2670308.75</td>\n",
       "      <td>2555663.00</td>\n",
       "      <td>82.010184</td>\n",
       "      <td>38.400684</td>\n",
       "      <td>1493.581899</td>\n",
       "      <td>3.538684</td>\n",
       "      <td>...</td>\n",
       "      <td>0.136556</td>\n",
       "      <td>0.374267</td>\n",
       "      <td>-0.359334</td>\n",
       "      <td>-2.075864e-16</td>\n",
       "      <td>0.808360</td>\n",
       "      <td>0.836381</td>\n",
       "      <td>1.193275</td>\n",
       "      <td>0.612878</td>\n",
       "      <td>0.606401</td>\n",
       "      <td>0.974770</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3039</th>\n",
       "      <td>DEU</td>\n",
       "      <td>Germany</td>\n",
       "      <td>Euro</td>\n",
       "      <td>1999</td>\n",
       "      <td>2768837.75</td>\n",
       "      <td>2641263.50</td>\n",
       "      <td>81.965830</td>\n",
       "      <td>38.979191</td>\n",
       "      <td>1478.722041</td>\n",
       "      <td>3.552474</td>\n",
       "      <td>...</td>\n",
       "      <td>0.139956</td>\n",
       "      <td>0.365609</td>\n",
       "      <td>-0.357325</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.758368</td>\n",
       "      <td>0.812084</td>\n",
       "      <td>1.107785</td>\n",
       "      <td>0.606163</td>\n",
       "      <td>0.603862</td>\n",
       "      <td>0.954278</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 47 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     countrycode  country currency_unit  year       rgdpe       rgdpo  \\\n",
       "3035         DEU  Germany          Euro  1995  2444280.75  2376434.00   \n",
       "3036         DEU  Germany          Euro  1996  2474957.50  2409760.75   \n",
       "3037         DEU  Germany          Euro  1997  2565733.00  2481533.50   \n",
       "3038         DEU  Germany          Euro  1998  2670308.75  2555663.00   \n",
       "3039         DEU  Germany          Euro  1999  2768837.75  2641263.50   \n",
       "\n",
       "            pop        emp          avh        hc  ...     csh_g     csh_x  \\\n",
       "3035  81.612900  37.939034  1527.978292  3.497632  ...  0.135220  0.348669   \n",
       "3036  81.870772  37.959774  1510.495404  3.511262  ...  0.134964  0.346536   \n",
       "3037  81.993831  37.939022  1499.644241  3.524946  ...  0.136400  0.346886   \n",
       "3038  82.010184  38.400684  1493.581899  3.538684  ...  0.136556  0.374267   \n",
       "3039  81.965830  38.979191  1478.722041  3.552474  ...  0.139956  0.365609   \n",
       "\n",
       "         csh_m         csh_r      pl_c      pl_i      pl_g      pl_x  \\\n",
       "3035 -0.361674  0.000000e+00  1.033949  0.952057  1.559026  0.694944   \n",
       "3036 -0.353329  1.859867e-16  0.976098  0.934430  1.514511  0.696348   \n",
       "3037 -0.342708  0.000000e+00  0.834261  0.826947  1.250930  0.656168   \n",
       "3038 -0.359334 -2.075864e-16  0.808360  0.836381  1.193275  0.612878   \n",
       "3039 -0.357325  0.000000e+00  0.758368  0.812084  1.107785  0.606163   \n",
       "\n",
       "          pl_m      pl_k  \n",
       "3035  0.655703  1.145803  \n",
       "3036  0.658500  1.094040  \n",
       "3037  0.633227  0.969747  \n",
       "3038  0.606401  0.974770  \n",
       "3039  0.603862  0.954278  \n",
       "\n",
       "[5 rows x 47 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "penn.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We now compute variables"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Construct Variables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:28:18.868130Z",
     "start_time": "2019-05-23T21:28:18.802311Z"
    }
   },
   "outputs": [],
   "source": [
    "penn = penn[['country','year','pop','rconna','rgdpna','rkna']]\n",
    "penn['year'] = penn['year'].astype(str)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We use real consumption at 2011 level National prices (in millions, 2011 US)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:28:19.873183Z",
     "start_time": "2019-05-23T21:28:19.596214Z"
    }
   },
   "outputs": [],
   "source": [
    "penn['csy'] = penn['rconna']/penn['rgdpna']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We use the capital stock at constant 2011 National prices (in millions, 2011 US)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:28:44.515558Z",
     "start_time": "2019-05-23T21:28:44.511882Z"
    }
   },
   "outputs": [],
   "source": [
    "penn['ksy'] = penn['rkna']/penn['rgdpna']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We compute GDP per capita using real GDP at constant 2011 prices (in millions 2011 US) and divide by total population (in millions)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:29:10.283912Z",
     "start_time": "2019-05-23T21:29:10.280549Z"
    }
   },
   "outputs": [],
   "source": [
    "penn['rgdpnap'] = penn['rgdpna']/penn['pop']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We compute deviations relative to US."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:29:37.119258Z",
     "start_time": "2019-05-23T21:29:36.845617Z"
    }
   },
   "outputs": [],
   "source": [
    "temp = penn[['rgdpnap','country','year']]\n",
    "temp = temp.set_index(['year','country'])\n",
    "temp = temp.unstack()\n",
    "for c in cnames[1:]:\n",
    "    temp['rgdpnap'][c] = temp['rgdpnap'][c]/temp['rgdpnap']['United States']\n",
    "temp['rgdpnap']['United States'] = temp['rgdpnap']['United States']/temp['rgdpnap']['United States']\n",
    "temp = temp.stack()\n",
    "temp.columns = ['ys']\n",
    "ys = temp.reset_index().set_index(['country','year']).sort_index()\n",
    "penn = penn.set_index(['country','year'])\n",
    "penn = penn.merge(ys,left_index=True,right_index=True)\n",
    "penn = penn[['csy','ksy','ys']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We have the following moments across countries and years"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:30:12.052365Z",
     "start_time": "2019-05-23T21:30:12.035116Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>csy</th>\n",
       "      <th>ksy</th>\n",
       "      <th>ys</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>160.000000</td>\n",
       "      <td>160.000000</td>\n",
       "      <td>160.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.744910</td>\n",
       "      <td>4.226871</td>\n",
       "      <td>0.814297</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.047945</td>\n",
       "      <td>0.650458</td>\n",
       "      <td>0.108000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.636059</td>\n",
       "      <td>2.962467</td>\n",
       "      <td>0.599292</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.710768</td>\n",
       "      <td>3.902014</td>\n",
       "      <td>0.735718</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.751858</td>\n",
       "      <td>4.240006</td>\n",
       "      <td>0.820280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.770197</td>\n",
       "      <td>4.552309</td>\n",
       "      <td>0.883126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>0.851606</td>\n",
       "      <td>5.936691</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              csy         ksy          ys\n",
       "count  160.000000  160.000000  160.000000\n",
       "mean     0.744910    4.226871    0.814297\n",
       "std      0.047945    0.650458    0.108000\n",
       "min      0.636059    2.962467    0.599292\n",
       "25%      0.710768    3.902014    0.735718\n",
       "50%      0.751858    4.240006    0.820280\n",
       "75%      0.770197    4.552309    0.883126\n",
       "max      0.851606    5.936691    1.000000"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "penn.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>csy</th>\n",
       "      <th>ksy</th>\n",
       "      <th>ys</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>country</th>\n",
       "      <th>year</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">Germany</th>\n",
       "      <th>1995</th>\n",
       "      <td>0.770485</td>\n",
       "      <td>3.612009</td>\n",
       "      <td>0.864700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1996</th>\n",
       "      <td>0.775610</td>\n",
       "      <td>3.668945</td>\n",
       "      <td>0.847332</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1997</th>\n",
       "      <td>0.767639</td>\n",
       "      <td>3.685918</td>\n",
       "      <td>0.835105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1998</th>\n",
       "      <td>0.763689</td>\n",
       "      <td>3.702503</td>\n",
       "      <td>0.825562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1999</th>\n",
       "      <td>0.765286</td>\n",
       "      <td>3.723471</td>\n",
       "      <td>0.814552</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   csy       ksy        ys\n",
       "country year                              \n",
       "Germany 1995  0.770485  3.612009  0.864700\n",
       "        1996  0.775610  3.668945  0.847332\n",
       "        1997  0.767639  3.685918  0.835105\n",
       "        1998  0.763689  3.702503  0.825562\n",
       "        1999  0.765286  3.723471  0.814552"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "penn.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# GDP Share of Expenditures"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We take the GDP share of medical expenditures (all financing sources) from OECD Health Data 2018. We process the table downloaded directly from OECD."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:31:30.051482Z",
     "start_time": "2019-05-23T21:31:30.034976Z"
    }
   },
   "outputs": [],
   "source": [
    "labels = ['country','unit','scrap']\n",
    "for t in range(1995,2016):\n",
    "    labels.append(str(t))\n",
    "oecd = pd.read_excel(data+'oecd/oecd-shares-1995-2015.xlsx',skiprows=7,skipfooter=3)\n",
    "oecd.columns = labels\n",
    "oecd = oecd.drop(columns=['scrap','unit'])\n",
    "oecd = oecd.set_index('country')\n",
    "oecd = oecd.stack().to_frame()\n",
    "oecd.columns = ['s']\n",
    "oecd['s'] = oecd['s']/100.0\n",
    "oecd.index.names = ['country','year']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>s</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>country</th>\n",
       "      <th>year</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">Denmark</th>\n",
       "      <th>1995</th>\n",
       "      <td>0.07771</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1996</th>\n",
       "      <td>0.07839</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1997</th>\n",
       "      <td>0.07750</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1998</th>\n",
       "      <td>0.07552</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1999</th>\n",
       "      <td>0.08342</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    s\n",
       "country year         \n",
       "Denmark 1995  0.07771\n",
       "        1996  0.07839\n",
       "        1997  0.07750\n",
       "        1998  0.07552\n",
       "        1999  0.08342"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "oecd.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We merge back to Penn Tables."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:31:45.625688Z",
     "start_time": "2019-05-23T21:31:45.617832Z"
    }
   },
   "outputs": [],
   "source": [
    "penn = penn.merge(oecd,left_index=True,right_index=True)\n",
    "penn = penn.reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>country</th>\n",
       "      <th>year</th>\n",
       "      <th>csy</th>\n",
       "      <th>ksy</th>\n",
       "      <th>ys</th>\n",
       "      <th>s</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Germany</td>\n",
       "      <td>1995</td>\n",
       "      <td>0.770485</td>\n",
       "      <td>3.612009</td>\n",
       "      <td>0.864700</td>\n",
       "      <td>0.09500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Germany</td>\n",
       "      <td>1996</td>\n",
       "      <td>0.775610</td>\n",
       "      <td>3.668945</td>\n",
       "      <td>0.847332</td>\n",
       "      <td>0.09785</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Germany</td>\n",
       "      <td>1997</td>\n",
       "      <td>0.767639</td>\n",
       "      <td>3.685918</td>\n",
       "      <td>0.835105</td>\n",
       "      <td>0.09664</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Germany</td>\n",
       "      <td>1998</td>\n",
       "      <td>0.763689</td>\n",
       "      <td>3.702503</td>\n",
       "      <td>0.825562</td>\n",
       "      <td>0.09687</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Germany</td>\n",
       "      <td>1999</td>\n",
       "      <td>0.765286</td>\n",
       "      <td>3.723471</td>\n",
       "      <td>0.814552</td>\n",
       "      <td>0.09768</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   country  year       csy       ksy        ys        s\n",
       "0  Germany  1995  0.770485  3.612009  0.864700  0.09500\n",
       "1  Germany  1996  0.775610  3.668945  0.847332  0.09785\n",
       "2  Germany  1997  0.767639  3.685918  0.835105  0.09664\n",
       "3  Germany  1998  0.763689  3.702503  0.825562  0.09687\n",
       "4  Germany  1999  0.765286  3.723471  0.814552  0.09768"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "penn.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Statistics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We compute consumption, net of medical spending, as the Penn stat includes  $s=\\frac{pm}{y}$\n",
    "  in  $\\frac{c}{y}$.\n",
    " ."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:32:41.166946Z",
     "start_time": "2019-05-23T21:32:41.163365Z"
    }
   },
   "outputs": [],
   "source": [
    "penn['cnsy'] = penn['csy'] - penn['s']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We compute means and standard errors by country over these years."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:32:59.670623Z",
     "start_time": "2019-05-23T21:32:59.613140Z"
    }
   },
   "outputs": [],
   "source": [
    "targets = penn[['cnsy','s','ys','ksy']].groupby(penn['country']).describe()\n",
    "targets = targets.reset_index()\n",
    "targets['co'] = targets['country'].replace(ce)\n",
    "targets.set_index('co',inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T21:33:06.533191Z",
     "start_time": "2019-05-23T21:33:06.512712Z"
    }
   },
   "outputs": [],
   "source": [
    "names = ['cnsy','s','ys','ksy']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Saving Targets"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We save means and standard error of the mean in moments directory."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>co</th>\n",
       "      <th>DK</th>\n",
       "      <th>FR</th>\n",
       "      <th>DE</th>\n",
       "      <th>IT</th>\n",
       "      <th>NL</th>\n",
       "      <th>SP</th>\n",
       "      <th>SE</th>\n",
       "      <th>US</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>cshare</th>\n",
       "      <td>0.572938</td>\n",
       "      <td>0.668806</td>\n",
       "      <td>0.645000</td>\n",
       "      <td>0.688474</td>\n",
       "      <td>0.615819</td>\n",
       "      <td>0.668007</td>\n",
       "      <td>0.645354</td>\n",
       "      <td>0.680889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mshare</th>\n",
       "      <td>0.090629</td>\n",
       "      <td>0.103574</td>\n",
       "      <td>0.102286</td>\n",
       "      <td>0.081089</td>\n",
       "      <td>0.088282</td>\n",
       "      <td>0.078123</td>\n",
       "      <td>0.085785</td>\n",
       "      <td>0.144225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>tfp</th>\n",
       "      <td>0.898205</td>\n",
       "      <td>0.735264</td>\n",
       "      <td>0.830156</td>\n",
       "      <td>0.739971</td>\n",
       "      <td>0.872562</td>\n",
       "      <td>0.640259</td>\n",
       "      <td>0.797962</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>kshare</th>\n",
       "      <td>4.134086</td>\n",
       "      <td>4.426736</td>\n",
       "      <td>3.807190</td>\n",
       "      <td>5.116111</td>\n",
       "      <td>4.294942</td>\n",
       "      <td>4.827075</td>\n",
       "      <td>4.131106</td>\n",
       "      <td>3.077725</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "co            DK        FR        DE        IT        NL        SP        SE  \\\n",
       "cshare  0.572938  0.668806  0.645000  0.688474  0.615819  0.668007  0.645354   \n",
       "mshare  0.090629  0.103574  0.102286  0.081089  0.088282  0.078123  0.085785   \n",
       "tfp     0.898205  0.735264  0.830156  0.739971  0.872562  0.640259  0.797962   \n",
       "kshare  4.134086  4.426736  3.807190  5.116111  4.294942  4.827075  4.131106   \n",
       "\n",
       "co            US  \n",
       "cshare  0.680889  \n",
       "mshare  0.144225  \n",
       "tfp     1.000000  \n",
       "kshare  3.077725  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "means = targets.loc[:,targets.columns.get_level_values(1)=='mean']\n",
    "means.columns = ['cshare','mshare','tfp','kshare']\n",
    "\n",
    "stds = targets.loc[:,targets.columns.get_level_values(1)=='std']\n",
    "stds.columns = ['cshare','mshare','tfp','kshare']\n",
    "\n",
    "means.transpose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0876095, 0.7831693755107656)"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "means.loc[['DK','SE','FR','IT','NL','SP','SE'],'mshare'].mean(),means.loc[['DK','SE','FR','IT','NL','SP','SE'],'tfp'].mean()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "means.transpose().to_pickle('../estimation/moments/means_macro.pkl')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>co</th>\n",
       "      <th>DK</th>\n",
       "      <th>FR</th>\n",
       "      <th>DE</th>\n",
       "      <th>IT</th>\n",
       "      <th>NL</th>\n",
       "      <th>SP</th>\n",
       "      <th>SE</th>\n",
       "      <th>US</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>cshare</th>\n",
       "      <td>0.013745</td>\n",
       "      <td>0.008414</td>\n",
       "      <td>0.022548</td>\n",
       "      <td>0.008546</td>\n",
       "      <td>0.020319</td>\n",
       "      <td>0.007993</td>\n",
       "      <td>0.035526</td>\n",
       "      <td>0.009079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mshare</th>\n",
       "      <td>0.009913</td>\n",
       "      <td>0.007025</td>\n",
       "      <td>0.005096</td>\n",
       "      <td>0.007282</td>\n",
       "      <td>0.014508</td>\n",
       "      <td>0.009155</td>\n",
       "      <td>0.013101</td>\n",
       "      <td>0.016178</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>tfp</th>\n",
       "      <td>0.027095</td>\n",
       "      <td>0.012841</td>\n",
       "      <td>0.024683</td>\n",
       "      <td>0.046430</td>\n",
       "      <td>0.018157</td>\n",
       "      <td>0.021694</td>\n",
       "      <td>0.032258</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>kshare</th>\n",
       "      <td>0.250125</td>\n",
       "      <td>0.199957</td>\n",
       "      <td>0.109525</td>\n",
       "      <td>0.444126</td>\n",
       "      <td>0.143179</td>\n",
       "      <td>0.532728</td>\n",
       "      <td>0.257594</td>\n",
       "      <td>0.074448</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "co            DK        FR        DE        IT        NL        SP        SE  \\\n",
       "cshare  0.013745  0.008414  0.022548  0.008546  0.020319  0.007993  0.035526   \n",
       "mshare  0.009913  0.007025  0.005096  0.007282  0.014508  0.009155  0.013101   \n",
       "tfp     0.027095  0.012841  0.024683  0.046430  0.018157  0.021694  0.032258   \n",
       "kshare  0.250125  0.199957  0.109525  0.444126  0.143179  0.532728  0.257594   \n",
       "\n",
       "co            US  \n",
       "cshare  0.009079  \n",
       "mshare  0.016178  \n",
       "tfp     0.000000  \n",
       "kshare  0.074448  "
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stds.transpose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "stds.transpose().to_pickle('../estimation/moments/stds_macro.pkl')"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "cf2a50979671a58939829e6829efb726aa5da11149213b77bd50351f899d04fb"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
